;----- Paragraph @tuneload@ -----


clean_c100

	ldx #0
	txa

cc100	sta $c100,x
	sta $c200,x
	sta $c300,x
	sta $c400,x

	sta $c500,x
	sta $c600,x
	sta $c700,x
	sta $c800,x

	sta $c900,x
	sta $ca00,x
	sta $cb00,x
	dex

	bne cc100
	rts

compute_tune_l

	lda #$ff
	sta ctll
	lda #$cb
	sta ctlh

;

ctl3	lda ctll
	bne ctl2
	dec ctlh
ctl2
	dec ctll

ctll = *+1
ctlh = *+2
	lda $cbff ; selfmod addy


	beq ctl3

	inc ctll

	rts


;----------------------------
; TUNELOAD

selline .byte 0
nowplaying .byte 0	; tune playing currently

tuneload
	
	jsr clk_reset
	
	lda liczba
	sta liczba_tmp


	lda selline
	beq _xt1
	cmp #1
	bne _xt2
	inc liczba
	jmp _xt1

_xt2	; selline = 2	

	inc liczba
	inc liczba

_xt1 	lda #iload
	sta $6c00-1

	lda liczba	
	sta nowplaying

	jsr przelicz

        jsr loading
;        jsr wakeup

	jsr clean_c100


	lda #iload
      	sta $6c00-1

_lipa	
	ldx #<fname
	ldy #>fname
	lda #fnamel
	
	jsr loadfile
       
       	inc $d020
       	dec $d020
       
        bcs __lipa

	jmp _tload

;

__lipa	lda #idisk
	sta $6c00-1

	jmp _lipa

temptemp .byte 0
;

_tload
      	lda #iload
      	sta $6c00-1

	;depakowanie


	jsr compute_tune_l

	lda ctll
	;lda #$5d
	sta $930f
	lda ctlh
	;lda #$c9
	sta $9310

        jsr stop

	lda #iunpack
	sta $6c00-1

	jsr $9312 ; exomizer: decrunch_file

        jsr loaded


	lda #$00
	tax
	tay

	jsr init

	lda liczba_tmp
	sta liczba

	jsr rysuj

	rts
